using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVDTPLAN
    {
        public DataRow Convert2VDTPLAN(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVDTPLAN(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VDTMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VDTLO"] = " ".PadRight(2 ); 
         dwReturn["VDTVART"] = " ".PadRight(3 ); 
         dwReturn["VDTSPED"] = " ".PadRight(3 ); 
         dwReturn["VDTJJJJ"] = " ".PadRight(0 ); 
         dwReturn["VDTMM"] = " ".PadRight(0 ); 
         dwReturn["VDTTAG01"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG02"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG03"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG04"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG05"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG06"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG07"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG08"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG09"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG10"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG11"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG12"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG13"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG14"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG15"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG16"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG17"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG18"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG19"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG20"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG21"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG22"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG23"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG24"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG25"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG26"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG27"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG28"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG29"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG30"] = " ".PadRight(1 ); 
         dwReturn["VDTTAG31"] = " ".PadRight(1 ); 
         dwReturn["VDTANZTAG"] = " ".PadRight(2 ); 
         dwReturn["VDTVERSATZ"] = " ".PadRight(2 ); 
         dwReturn["VDTFILLER"] = " ".PadRight(147 ); 
         dwReturn["VDTAENZL"] = " ".PadRight(0 ); 
         dwReturn["VDTAENB"] = " ".PadRight(8 ); 
         dwReturn["VDTAEND"] = " ".PadRight(0 ); 
         dwReturn["VDTNEUB"] = " ".PadRight(8 ); 
         dwReturn["VDTNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVDTPLAN(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVDTPLAN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVDTPLAN(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVDTPLAN(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVDTPLAN(dwLocal, ITXDBVERSION);
            }
            UpdateVDTPLAN(dwLocal);
        }
        public void InsertVDTPLAN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VDTPLAN(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVDTPLAN(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VDTPLAN WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VDTPLAN  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VDTPLAN";
            Return = Result;
            return Return;
        }
        public void DeleteVDTPLAN(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VDTPLAN   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVDTPLAN(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VDTPLAN SET "
                    +"VDTMANDANT= :VDTMANDANT,"
                    +"VDTLO= :VDTLO,"
                    +"VDTVART= :VDTVART,"
                    +"VDTSPED= :VDTSPED,"
                    +"VDTJJJJ= :VDTJJJJ,"
                    +"VDTMM= :VDTMM,"
                    +"VDTTAG01= :VDTTAG01,"
                    +"VDTTAG02= :VDTTAG02,"
                    +"VDTTAG03= :VDTTAG03,"
                    +"VDTTAG04= :VDTTAG04,"
                    +"VDTTAG05= :VDTTAG05,"
                    +"VDTTAG06= :VDTTAG06,"
                    +"VDTTAG07= :VDTTAG07,"
                    +"VDTTAG08= :VDTTAG08,"
                    +"VDTTAG09= :VDTTAG09,"
                    +"VDTTAG10= :VDTTAG10,"
                    +"VDTTAG11= :VDTTAG11,"
                    +"VDTTAG12= :VDTTAG12,"
                    +"VDTTAG13= :VDTTAG13,"
                    +"VDTTAG14= :VDTTAG14,"
                    +"VDTTAG15= :VDTTAG15,"
                    +"VDTTAG16= :VDTTAG16,"
                    +"VDTTAG17= :VDTTAG17,"
                    +"VDTTAG18= :VDTTAG18,"
                    +"VDTTAG19= :VDTTAG19,"
                    +"VDTTAG20= :VDTTAG20,"
                    +"VDTTAG21= :VDTTAG21,"
                    +"VDTTAG22= :VDTTAG22,"
                    +"VDTTAG23= :VDTTAG23,"
                    +"VDTTAG24= :VDTTAG24,"
                    +"VDTTAG25= :VDTTAG25,"
                    +"VDTTAG26= :VDTTAG26,"
                    +"VDTTAG27= :VDTTAG27,"
                    +"VDTTAG28= :VDTTAG28,"
                    +"VDTTAG29= :VDTTAG29,"
                    +"VDTTAG30= :VDTTAG30,"
                    +"VDTTAG31= :VDTTAG31,"
                    +"VDTANZTAG= :VDTANZTAG,"
                    +"VDTVERSATZ= :VDTVERSATZ,"
                    +"VDTFILLER= :VDTFILLER,"
                    +"VDTAENZL= :VDTAENZL,"
                    +"VDTAENB= :VDTAENB,"
                    +"VDTAEND= :VDTAEND,"
                    +"VDTNEUB= :VDTNEUB,"
                    +"VDTNEUD= :VDTNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VDTMANDANT", OracleType.NVarChar).Value = dwData["VDTMANDANT"].ToString(); 
          or1.Parameters.Add("VDTLO", OracleType.NVarChar).Value = dwData["VDTLO"].ToString(); 
          or1.Parameters.Add("VDTVART", OracleType.NVarChar).Value = dwData["VDTVART"].ToString(); 
          or1.Parameters.Add("VDTSPED", OracleType.NVarChar).Value = dwData["VDTSPED"].ToString(); 
          or1.Parameters.Add("VDTJJJJ", OracleType.NVarChar).Value = dwData["VDTJJJJ"].ToString(); 
          or1.Parameters.Add("VDTMM", OracleType.NVarChar).Value = dwData["VDTMM"].ToString(); 
          or1.Parameters.Add("VDTTAG01", OracleType.NVarChar).Value = dwData["VDTTAG01"].ToString(); 
          or1.Parameters.Add("VDTTAG02", OracleType.NVarChar).Value = dwData["VDTTAG02"].ToString(); 
          or1.Parameters.Add("VDTTAG03", OracleType.NVarChar).Value = dwData["VDTTAG03"].ToString(); 
          or1.Parameters.Add("VDTTAG04", OracleType.NVarChar).Value = dwData["VDTTAG04"].ToString(); 
          or1.Parameters.Add("VDTTAG05", OracleType.NVarChar).Value = dwData["VDTTAG05"].ToString(); 
          or1.Parameters.Add("VDTTAG06", OracleType.NVarChar).Value = dwData["VDTTAG06"].ToString(); 
          or1.Parameters.Add("VDTTAG07", OracleType.NVarChar).Value = dwData["VDTTAG07"].ToString(); 
          or1.Parameters.Add("VDTTAG08", OracleType.NVarChar).Value = dwData["VDTTAG08"].ToString(); 
          or1.Parameters.Add("VDTTAG09", OracleType.NVarChar).Value = dwData["VDTTAG09"].ToString(); 
          or1.Parameters.Add("VDTTAG10", OracleType.NVarChar).Value = dwData["VDTTAG10"].ToString(); 
          or1.Parameters.Add("VDTTAG11", OracleType.NVarChar).Value = dwData["VDTTAG11"].ToString(); 
          or1.Parameters.Add("VDTTAG12", OracleType.NVarChar).Value = dwData["VDTTAG12"].ToString(); 
          or1.Parameters.Add("VDTTAG13", OracleType.NVarChar).Value = dwData["VDTTAG13"].ToString(); 
          or1.Parameters.Add("VDTTAG14", OracleType.NVarChar).Value = dwData["VDTTAG14"].ToString(); 
          or1.Parameters.Add("VDTTAG15", OracleType.NVarChar).Value = dwData["VDTTAG15"].ToString(); 
          or1.Parameters.Add("VDTTAG16", OracleType.NVarChar).Value = dwData["VDTTAG16"].ToString(); 
          or1.Parameters.Add("VDTTAG17", OracleType.NVarChar).Value = dwData["VDTTAG17"].ToString(); 
          or1.Parameters.Add("VDTTAG18", OracleType.NVarChar).Value = dwData["VDTTAG18"].ToString(); 
          or1.Parameters.Add("VDTTAG19", OracleType.NVarChar).Value = dwData["VDTTAG19"].ToString(); 
          or1.Parameters.Add("VDTTAG20", OracleType.NVarChar).Value = dwData["VDTTAG20"].ToString(); 
          or1.Parameters.Add("VDTTAG21", OracleType.NVarChar).Value = dwData["VDTTAG21"].ToString(); 
          or1.Parameters.Add("VDTTAG22", OracleType.NVarChar).Value = dwData["VDTTAG22"].ToString(); 
          or1.Parameters.Add("VDTTAG23", OracleType.NVarChar).Value = dwData["VDTTAG23"].ToString(); 
          or1.Parameters.Add("VDTTAG24", OracleType.NVarChar).Value = dwData["VDTTAG24"].ToString(); 
          or1.Parameters.Add("VDTTAG25", OracleType.NVarChar).Value = dwData["VDTTAG25"].ToString(); 
          or1.Parameters.Add("VDTTAG26", OracleType.NVarChar).Value = dwData["VDTTAG26"].ToString(); 
          or1.Parameters.Add("VDTTAG27", OracleType.NVarChar).Value = dwData["VDTTAG27"].ToString(); 
          or1.Parameters.Add("VDTTAG28", OracleType.NVarChar).Value = dwData["VDTTAG28"].ToString(); 
          or1.Parameters.Add("VDTTAG29", OracleType.NVarChar).Value = dwData["VDTTAG29"].ToString(); 
          or1.Parameters.Add("VDTTAG30", OracleType.NVarChar).Value = dwData["VDTTAG30"].ToString(); 
          or1.Parameters.Add("VDTTAG31", OracleType.NVarChar).Value = dwData["VDTTAG31"].ToString(); 
          or1.Parameters.Add("VDTANZTAG", OracleType.NVarChar).Value = dwData["VDTANZTAG"].ToString(); 
          or1.Parameters.Add("VDTVERSATZ", OracleType.NVarChar).Value = dwData["VDTVERSATZ"].ToString(); 
          or1.Parameters.Add("VDTFILLER", OracleType.NVarChar).Value = dwData["VDTFILLER"].ToString(); 
          or1.Parameters.Add("VDTAENZL", OracleType.NVarChar).Value = dwData["VDTAENZL"].ToString(); 
          or1.Parameters.Add("VDTAENB", OracleType.NVarChar).Value = dwData["VDTAENB"].ToString(); 
          or1.Parameters.Add("VDTAEND", OracleType.NVarChar).Value = dwData["VDTAEND"].ToString(); 
          or1.Parameters.Add("VDTNEUB", OracleType.NVarChar).Value = dwData["VDTNEUB"].ToString(); 
          or1.Parameters.Add("VDTNEUD", OracleType.NVarChar).Value = dwData["VDTNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
